﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using FluorineFx;

namespace App_Code.Conexao
{
    public enum DataSource
    {
        FlexPront
    }

    [RemotingService]
    [Serializable]
    public class ConfiguradorConexao
    {
        public ConfiguradorConexao(string urlBd)
        {
            UrlBd = urlBd;
        }

        private string UrlBd { get; set; }
        private static SortedList<DataSource, ConfiguradorConexao> _connectionsConfigurations;

        public SqlConnection Conn
        {
            get
            {
                return new SqlConnection(UrlBd);
            }
        }

        public static Dictionary<DataSource, ConfiguradorConexao> ConfiguracaoConexao
        {
            get
            {
                if (_connectionsConfigurations == null)
                {
                    LoadConfiguration();
                }

                return new Dictionary<DataSource, ConfiguradorConexao>(_connectionsConfigurations);
            }
        }

        private static void LoadConfiguration()
        {
            if (_connectionsConfigurations == null)
            {
                if (_connectionsConfigurations == null)
                {
                    _connectionsConfigurations = new SortedList<DataSource, ConfiguradorConexao>();
                }

                BuildSqlConnections();
            }
        }

        private static ConfiguradorConexao GetConnectionConfigurator(string urlBD)
        {
            var result = new ConfiguradorConexao(urlBD);
            return result;
        }

        public static void BuildSqlConnections()
        {
            string resultado = "Data Source=NATHAN-PC\\SQLEXPRESS;Initial Catalog=FlexPront;Integrated Security=True;";
            ConfiguradorConexao configurator = GetConnectionConfigurator(resultado);

            _connectionsConfigurations.Add(DataSource.FlexPront, configurator);

        }
    }
}
